<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/9/25
 * Time: 12:56
 */

namespace Admin\Controller;
use Think\Controller;
use Think\Model;

class FinanceController extends BaseController {

    public function account()
    {
        $type = I('get.type');
        $start_time = I('get.start_time');
        $finish_time = I('get.finish_time');
        $model = new Model();
        $sql = "select a.user_id,a.nickname,a.header_pic,b.time,b.type,b.total_amount from wl_userinfo a ,wl_pay_record b where a.user_id=b.user_id";
        if(!empty($type))
        {
            if($type==1)
            {
                $sql.= " and b.type=$type";
            }else{
                $sql.=" and b.type!=1";
            }
        }
        if($start_time&&$finish_time)
        {
            $sql.=" and b.time>='$start_time' and b.time<='$finish_time'";
        }
        $sql.=" order by b.time desc";
        $data = $model->query($sql);
        $count = count($data);
        $Page = new \Think\Page($count, 10);// 实例化分页类
        $show = $Page->show();// 分页显示输出
        $sql .= " limit $Page->firstRow,$Page->listRows";
        $list = $model->query($sql);
        $this->assign('data', $list);// 赋值数据集$this->assign('page',$show);// 赋值分页输出
        $this->assign('page',$show);
        $this->display();
    }

    //认证费设置
    public function auth_setting()
    {
        $model = D('charge');
        $condition['type'] = 1;
        $result = $model->where($condition)->select();
        $charge = $result[0]['charge'];
        $this->assign('charge',$charge);
        $this->display();
    }

    //更改认证费
    public function change_auth_charge()
    {
        $model = D('charge');
        $new_price = I('post.new_price');
       $this->change_charge($new_price,1);
       $this->redirect('finance/auth_setting');
    }

    //更改会员费
    public function change_member_setting()
    {
        $data = $_POST;
        $type = array(
            'one'=>2,
            'three'=>3,
            'six'=>4,
            'twelve'=>5
        );
        foreach($data as $key=>$value)
        {
            if(!empty($data[$key]))
            {
                $this->change_charge($data[$key], $type[$key]);
            }
        }
        $this->redirect('finance/member_setting');
    }

    public function change_charge($charge,$type)
    {
        $model = D('charge');
        $data['charge'] = $charge;
        $condition['type'] = $type;
        $model->where($condition)->save($data);
    }

    //会员费设置
    public function member_setting()
    {
        $model = D('charge');
        $data = $model->where('type!=1')->select();
        $this->assign('data',$data);
        $this->display();
    }

}